package com.jzy.gulimall.testssoclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * @author jzy
 * @date 2020/9/17 21:02
 */
@Controller
public class HelloController {

    @Value("${sso.server.url}")
    private String ssoServerUrl;

    //无需登录
    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }

    @GetMapping("/employee")
    public String employee(Model model, HttpSession session){
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser==null) {
            return "redirect:"+ssoServerUrl+"?redirect=http://client1.com/employee";
        }
        ArrayList<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        model.addAttribute("list", list);
        return "list";
    }
}
